package com.open.capacity.reimburse.controller;

import java.util.Map;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.reimburse.entity.BillReception1;
import com.open.capacity.reimburse.service.BillReception1Service;

import com.open.capacity.commons.PageResult;
import javax.validation.Valid;
/**
 * 公务接待申请表
 *
 * @author 
 * @email 
 * @date 2021-05-11 17:51:27
 */
@RestController
@RequestMapping("reception1s")
@Api(tags = "公务接待申请表")
public class BillReception1Controller {

    @Autowired
    private BillReception1Service billReception1Service;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @PreAuthorize("hasAnyAuthority('bill_reception1:billreception1:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = billReception1Service.pageAll(params);
        return pageResult;
    }

    /**
    * 查询单条记录
    */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('bill_reception1:billreception1:list')")
    public Result findById(String id) {
        return Result.succeed(billReception1Service.findById(id));
    }


    /**
     * 查询单条记录
     */
    @RequestMapping("/findByProcessId")
    @PreAuthorize("hasAnyAuthority('bill_reception1:billreception1:list')")
    public Result findByProcessId(String processId) {
        return Result.succeed(billReception1Service.findById(processId));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('bill_reception1:billreception1:save')")
    public Result save(@RequestBody @Valid  BillReception1 billReception1, String keyValue, Integer force) {
    	 if(StringUtils.isEmpty(keyValue)) {
              billReception1Service.save(billReception1);
	     }else {
          billReception1.setId(keyValue);
          billReception1Service.update(billReception1);
	     }
        return Result.succeed("操作成功");
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('bill_reception1:billreception1:delete')")
    public Result delete(@PathVariable String  id) {
            billReception1Service.delete(id);
        return Result.succeed("删除成功");
    }

}
